/**
 * Created by LIQU3 on 8/25/2016.
 */
angular.module("recommendApp", [])
    .controller("RecommendController", function ($scope, $http) {
        var req={
            method:"GET",
            url:"CHa/dishes?recommend=2"
        };
        $http(req)
            .then(function (res) {
                $scope.dishes=res.data;
            });
    })
    .controller("MerchantController", function ($scope, $http) {
        var req={
            method:"GET",
            url:"CHa/merchants"
        };
        $http(req)
            .then(function (res) {
                $scope.merchants=res.data;
                $scope.merchants.forEach(function (merchant,index) {
                    var starlist = [];
                    for(var i = 0;i<merchant.star;i++){
                        starlist.push(i);
                    }
                    $scope.merchants[index].starlist = starlist;
                });
            });
    })
    .controller('userCtrl',function ($scope,$http) {
        var req = {
            method:"GET",
            url:"/CHa/session"
        }

        $http(req)
            .then(function (res) {
                if(res.data.account!=undefined){
                    $scope.userAccount = res.data.account;
                    $scope.hasLogin = true;
                }else{
                    $scope.hasLogin = false;
                }


            });

        $scope.logOut = function () {
            var clearSeesionReq = {
                url:"/CHa/session",
                method:"PUT"
            }
            $http(clearSeesionReq).then(function (res) {
                window.location.href = "home.html";
            })

        }
    });
